package com.zthz.douxing.sendmessageservice.service

import com.zthz.douxing.event.UserWillDepartEvent
import com.zthz.douxing.exception.GeTuiSendMessageException
import com.zthz.douxing.msg.MessageType
import grails.transaction.Transactional

@Transactional
class BeginStartGoMessageService extends AbstractSendMessageService {

    @Override
    protected String sendMessage(UserWillDepartEvent userWillDepartEvent) {
        String sendResult = null
        String message = null
        try{
            message  = orderXingeMessageService.orderMessage(userWillDepartEvent)
            if(isNullMessage(message)){
                sendResult = "ERROR"
                return sendResult
            }
            Map param = geTuiMessageSenderService.getParamFromUserWillDepartEvent4PlanForm(
                     userWillDepartEvent,message,MessageType.PlanInfo)
            sendResult = geTuiMessageSenderService.send2One(param)
        }catch (GeTuiSendMessageException e){
            sendResult = "ERROR"
            throw e
        } catch (Exception e){
            sendResult = "ERROR"
        }finally{
            orderXingeMessageService.saveMessageToUserLog(userWillDepartEvent,
                    message,sendResult,MessageType.PlanInfo)
        }
        return  sendResult
    }
}
